package com.sjgs.gis.domain;


import com.fasterxml.jackson.annotation.JsonFormat;
//import com.sjgs.gis.annotation.AutoIncKey;
import com.sjgs.common.utils.FileNameUtils;
import com.sjgs.gis.domain.enumeration.DataFileStatus;
import com.sjgs.gis.domain.enumeration.DataFileType;
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;
//import org.springframework.data.mongodb.core.index.Indexed;
//import org.springframework.data.mongodb.core.mapping.Document;
//import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;

import static com.sjgs.common.Constants.DEFAULT_DATE_TIME_FORMAT;


/**
 * A File.
 */
@Table(value = "datafile")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
//@Document
@Data
public class DataFile implements Serializable {
    private static final long serialVersionUID = 1L;
    //@AutoIncKey
    @Id
    Long id = null;

    //@Indexed(unique = true)
    @NonNull
    String fkey = "";

    @NonNull
    Long fsize = 0L;

    @Column(value = "mime_type")
    //@Field("mime_type")
            String mimeType = null;


    String dir = "/";

    /*
     *  存储模式: LOCAL,CLUSTER,HDFS,GRIDFS
     */
    Integer type = DataFileType.LOCAL.ordinal();

    String url = "";

    @Column(value = "mirro_url")
    String mirroUrl = "";

    @Column(value = "put_time")
    //@Field("put_time")
    @DateTimeFormat(pattern = DEFAULT_DATE_TIME_FORMAT)
    @JsonFormat(pattern = DEFAULT_DATE_TIME_FORMAT)
    LocalDateTime putTime = LocalDateTime.now();

    @Column(value = "update_time")
    //@Field("update_time")
    @DateTimeFormat(pattern = DEFAULT_DATE_TIME_FORMAT)
    @JsonFormat(pattern = DEFAULT_DATE_TIME_FORMAT)
    LocalDateTime updateTime = LocalDateTime.now();

    @Column(value = "remaining_time")
    //@Field("remaining_time")
    @DateTimeFormat(pattern = DEFAULT_DATE_TIME_FORMAT)
    @JsonFormat(pattern = DEFAULT_DATE_TIME_FORMAT)
    LocalDateTime remainingTime = null;

    /*
     * 1-完整 0-不完整 2-remote
     */
    Integer status = DataFileStatus.PENDING.ordinal();

    public DataFile(String fkey, String dir, Integer type) {
        this.fkey = fkey;
        this.dir = dir;
        this.type = type;
    }

    public DataFile(String fkey, Long fsize, String mimeType) {
        this.fkey = fkey;
        this.fsize = fsize;
        this.mimeType = mimeType;
    }

    public String getFileName() {
        return FileNameUtils.getFileName(fkey);
    }

    public String getFileHash() {
        return FileNameUtils.getFileHash(fkey);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getFkey() {
        return fkey;
    }

    public void setFkey(String fkey) {
        this.fkey = fkey;
    }

    public Long getFsize() {
        return fsize;
    }

    public void setFsize(Long fsize) {
        this.fsize = fsize;
    }

    public String getMimeType() {
        return mimeType;
    }

    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    public String getDir() {
        return dir;
    }

    public void setDir(String dir) {
        this.dir = dir;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }


    public LocalDateTime getPutTime() {
        return putTime;
    }

    public void setPutTime(LocalDateTime putTime) {
        this.putTime = putTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public LocalDateTime getRemainingTime() {
        return remainingTime;
    }

    public void setRemainingTime(LocalDateTime remainingTime) {
        this.remainingTime = remainingTime;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getMirroUrl() {
        return mirroUrl;
    }

    public void setMirroUrl(String mirroUrl) {
        this.mirroUrl = mirroUrl;
    }
}
